# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
from cerbero.tools.libtool import LibtoolLibrary
from cerbero.tools.libtool import get_libtool_versions

class Recipe(recipe.Recipe):
    name = 'opus'
    version = '1.3.1'
    licenses = [{License.BSD_like: ['COPYING']}]
    stype = SourceType.TARBALL
    btype = BuildType.MESON
    url = 'xiph://.tar.gz'
    tarball_checksum = '65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d'
    meson_options = {
        'rtcd': 'enabled',
        'intrinsics': 'enabled',
        'extra-programs': 'disabled',
        'tests': 'disabled',
        'docs': 'disabled',
    }

    patches = [
        'opus/0001-celt-Force-stack-alignment-for-functions-using-__m12.patch',
        # https://gitlab.xiph.org/xiph/opus/-/merge_requests/13
        'opus/opus-meson-port.patch',
    ]

    files_libs = ['libopus']
    files_devel = ['include/opus', 'lib/pkgconfig/opus.pc']

    def prepare(self):
        # Always have NEON on ARM64, don't need to detect the CPU at runtime.
        if self.config.target_arch == Architecture.ARM64:
            self.meson_options['rtcd'] = 'disabled'

    def post_install(self):
        major, minor, micro = get_libtool_versions(self.version)
        LibtoolLibrary('opus', major, minor, micro,
                self.config.libdir, self.config.target_platform).save()
        super().post_install()
